package tests;

import static org.junit.Assert.*;

import java.io.IOException;
import java.net.UnknownHostException;

import mt.Order;
import mt.comm.ClientSideMessage;

import org.junit.Before;
import org.junit.Test;

import Network.ClientCommunication;
import Network.ServerCommunication;

public class ClientCommunicationTest {
	
	private ClientCommunication cliComm;
	private ServerCommunication serComm;
	private Order or_buy;
	private Order or_sell;

	@Before
	public void setUp() throws Exception {
		cliComm = new ClientCommunication();
		serComm = new ServerCommunication();
	}

	@Test
	public void test() throws UnknownHostException, IOException{
		serComm.start();
		cliComm.connect(null, "Norberto");
		try {
			Thread.sleep(500);
		} catch (InterruptedException e) {
			e.printStackTrace();
		}
		assertTrue(cliComm.isConnected());
		assertFalse(cliComm.hasNextMessage());
		cliComm.sendOrder(or_buy);
		assertEquals(cliComm.getNickname(),"Norberto");
		cliComm.disconnect();
		
		try {
			Thread.sleep(500);
		} catch (InterruptedException e) {
			e.printStackTrace();
		}
		assertTrue(cliComm.isConnected());

	}
}